using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
 

public partial class JobSeekers_resume : System.Web.UI.Page
{
     string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString =
             WebConfigurationManager.ConnectionStrings[
               "Database2000"].ConnectionString;
        if (Session.Contents["jsuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            txtContactEmail.Text = Convert.ToString(Session["jsemail"]);
            string resumeID = Request.QueryString.Get("ResumeID");
            if (!IsPostBack)
                EditResume(resumeID);
        }
        
    }
    void EditResume(string resumeID)
    {
        if (resumeID != "" && resumeID != null)
        {
            SqlServerProvider cls = new SqlServerProvider(connectionString);
            cls.CommandText = "select ResumeID,"+
            " UserID,ResumeTitle,ContactEmail, "+
            "Objective,ExperienceYear,"+
            "CurrentCompany,Viewable,"+
            "Confidental, TemplateResume "+
            " from tblJSResumes" +
            " where UserID=@UserID and ResumeID= @ResumeID ";
            cls.ParameterCollection = new string[2] { "@UserID", "@ResumeID" };
            cls.ValueCollection = new string[2] { Session["jsuserid"].ToString(), resumeID };
            
            DataTable dataTable = 
            cls.GetDataTable( );
             if(dataTable.Rows.Count>0)
            {
                ResumeID.Value = dataTable.Rows[0][0].ToString();            
                txtJob.Text=dataTable.Rows[0][2].ToString();
                txtContactEmail.Text=dataTable.Rows[0][3].ToString();
                txtObjective.Text=dataTable.Rows[0][4].ToString();
                ddlExperienceYear.SelectedValue=dataTable.Rows[0][5].ToString();
                txtCurrentCompany.Text=dataTable.Rows[0][6].ToString();
                ddlViewable.SelectedValue=dataTable.Rows[0][7].ToString();
                ddlTemplate.SelectedValue=dataTable.Rows[0][9].ToString();
                if (dataTable.Rows[0][8].ToString()=="True")
                    rdbConfidential.Checked =  true ;
                else
                    rdbNotConfidential.Checked = true;
            }
        }
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        SqlServerProvider cls = new SqlServerProvider(connectionString);
         
        string returnValue = cls.AddNewUpdateResume(
        ((ResumeID.Value != "") ? ResumeID.Value : "0"),
        Convert.ToString(Session.Contents["jsuserid"]),
        txtJob.Text, txtContactEmail.Text,
        txtObjective.Text,
        ddlExperienceYear.SelectedValue,
        txtCurrentCompany.Text,
        ddlViewable.SelectedValue,
        ddlTemplate.SelectedValue,
        rdbConfidential.Checked);
        if (cls.ErrorMessage!="")            
            literalError.Text = "Error: " + cls.ErrorMessage;
        else
            {
            if(ResumeID.Value!="")
                Session["ResumeID"] = ResumeID.Value;
            else
                Session["ResumeID"]= returnValue;
            Response.Redirect("resumedetails.aspx");
            }
    }
}
